package com.jz.community.moduleshoppingguide.neighbor.presenter;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.neighbor.bean.PublishTypeBean;
import com.jz.community.moduleshoppingguide.neighbor.bean.UploadImagesBean;
import com.jz.community.moduleshoppingguide.neighbor.model.NeighborModel;
import com.jz.community.moduleshoppingguide.neighbor.model.NeighborModelImp;
import com.jz.community.moduleshoppingguide.neighbor.ui.PublishMsgView;

import java.io.File;
import java.util.ArrayList;

public class PublishMessagePresenter extends BaseLifeCyclePresent<PublishMsgView.View> implements PublishMsgView.Presenter {

    private PublishMsgView.View view;
    private NeighborModel neighborModel;

    public PublishMessagePresenter(PublishMsgView.View view) {
        this.view = view;
        this.neighborModel = new NeighborModelImp(view.getContext());
    }


    @Override
    public void initTips() {
        neighborModel.initTips(new OnLoadListener<PublishTypeBean>() {
            @Override
            public void onSuccess(PublishTypeBean publishTypeBean) {
                view.setTipsData(publishTypeBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.tipsError(msg);

            }
        });
    }

    @Override
    public void upLoadImage(ArrayList<File> files) {
        neighborModel.uploadImages(files, new OnLoadListener<UploadImagesBean>() {
            @Override
            public void onSuccess(UploadImagesBean uploadImagesBean) {
                view.UploadSuccess(uploadImagesBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.UploadError(msg);

            }
        });

    }

    @Override
    public void publishMessage(String image_up, String content, String tip) {
        neighborModel.publishMessage(image_up, content, tip, new OnLoadListener<BaseResponseInfo>() {
            @Override
            public void onSuccess(BaseResponseInfo baseResponseInfo) {
                view.publishSuccess();
            }

            @Override
            public void onFail(String msg, int code) {
                view.publishError(msg);

            }
        });

    }
}
